{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "84ad9331",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "import random\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
    "imgG = cv2.GaussianBlur(gray,(3,3),0)#高斯滤波\n",
    "dst = cv2.Canny(img,50,50)#卷积\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1737244c",
   "metadata": {},
   "source": [
    "算子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1ca04d93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "import random\n",
    "import math\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
    "dst = np.zeros((height,width,1),np.uint8)\n",
    "for i in range(0,height-2):\n",
    "    for j in range(0,width-2):\n",
    "        gy = gray[i,j]*1+gray[i,j+1]*2+gray[i,j+2]*1-gray[i+2,j]*1-gray[i+2,j+1]*2-gray[i+2,j+2]*1\n",
    "        gx = gray[i,j]*1+gray[i+1,j]*2+gray[i+2,j]*1-gray[i,j+2]*1-gray[i+1,j+2]*2-gray[i+2,j+2]*1\n",
    "        grad = math.sqrt(gx*gx+gy*gy)\n",
    "        if grad>50:\n",
    "            dst[i,j] = 255\n",
    "        else:\n",
    "            dst[i,j] = 0\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ab90802",
   "metadata": {},
   "source": [
    "浮雕"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e09634cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "import random\n",
    "import math\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
    "#newP = gray0-gray1+150\n",
    "dst = np.zeros((height,width,1),np.uint8)\n",
    "for i in range(0,height):\n",
    "    for j in range(0,width-1):\n",
    "        gray0 = int(gray[i,j])\n",
    "        gray1 = int(gray[i,j+1])\n",
    "        newp = gray0 - gray1 + 150\n",
    "        if newp >255:\n",
    "            newp = 255\n",
    "        if newp < 0:\n",
    "            newp = 0\n",
    "        dst[i,j] = newp\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ce5c6b3",
   "metadata": {},
   "source": [
    "颜色风格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3734c7c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "import random\n",
    "import math\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "#rgb->new blue\n",
    "#b = b*1.5\n",
    "#g = g*1.5\n",
    "\n",
    "dst = np.zeros((height,width,3),np.uint8)\n",
    "for i in range(0,height):\n",
    "    for j in range(0,width-1):\n",
    "        (b,g,r)=img[i,j]\n",
    "        b = b*1.5\n",
    "        g = g*1.5\n",
    "        if b>255:\n",
    "            b = 255\n",
    "        if g>255:\n",
    "            g = 255\n",
    "        dst[i,j] = (b,g,r)\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c1c449b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "import random\n",
    "import math\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
    "#newP = gray0-gray1+150\n",
    "dst = np.zeros((height,width,3),np.uint8)\n",
    "for i in range(4,height-4):\n",
    "    for j in range(4,width-4):\n",
    "        array1 = np.zeros(8,np.uint8)\n",
    "        for m in range(-4,4):\n",
    "            for n in range(-4,4):\n",
    "                p1 = int(gray[i+m,j+n]/32)\n",
    "                array1[p1]=array1[p1]+1\n",
    "            currentMax = array1[0]\n",
    "            l = 0\n",
    "            for k in range(0,8):\n",
    "                if currentMax < array1[k]:\n",
    "                    currentMax = array1[k]\n",
    "                    l=k\n",
    "            for m in range(-4,4):\n",
    "                for n in range(-4,4):\n",
    "                    if gray[i+m,j+n]>=(l*32) and gray[i+m,j+n]<((l+1)*32):\n",
    "                        (b,g,r)=img[i+m,j+n]\n",
    "                dst[i,j]=(b,g,r)\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)\n",
    "                \n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "685961f4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
